<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('测试用例列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" id="planId" name="planId" th:value="${plan.id}">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <label>类型：</label>
                            <select name="type" th:with="type=${@dict.getType('test_case_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>模块ID：</label>
                            <input type="text" name="moduleId"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="selectCase()" shiro:hasPermission="system:plan:add">
                <i class="fa fa-plus"></i> 添加用例
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:plan:remove">
                <i class="fa fa-remove"></i> 批量删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:plan:export">
                <i class="fa fa-download"></i> 关闭
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:plan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:plan:remove')}]];
        var typeDatas = [[${@dict.getType('test_case_type')}]];
        var prefix = ctx + "system/plan/authCase";

        $(function() {
            var options = {
                url: prefix + "/allocatedList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "测试用例",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'precondition',
                    title: '前置条件'
                },
                {
                    field: 'module.name',
                    title: '模块'
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'updateBy',
                    title: '更新者'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAuthCase(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 分配用户-取消授权 */
		function cancelAuthCase(caseId) {
			$.modal.confirm("确认要取消该用户角色吗？", function() {
				$.operate.post(prefix + "/cancel", { "roleId": $("#planId").val(), "caseId": caseId });
		    })
		}

		/* 分配用户-选择用例 */
		function selectCase() {
			var url = prefix + '/selectCase/' + $("#planId").val();
		    $.modal.open("选择用例", url);
		}
    </script>
</body>
</html>